package com.dgut.utils;

import com.dgut.dao.IAccountDao;
import com.dgut.dao.impl.IAccountDaoImpl;
import com.dgut.service.IAccountService;
import com.dgut.service.impl.IAccountServiceImpl;

import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * bean:java类
 */
public class BeansFactory {

    private static Map<String,String> map = new HashMap<String, String>();

    static {
        InputStream inputStream = BeansFactory.class.getClassLoader().getResourceAsStream("beans.properties");
        Properties prop = new Properties();
        try {
            prop.load(inputStream);
            Enumeration<Object> keys = prop.keys();
            while (keys.hasMoreElements()){
                String key = (String) keys.nextElement();
                String value = prop.getProperty(key);
                System.out.println("key:"+key+" value:"+value);
                map.put(key,value);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static IAccountDao createAccountDao(){
        String name = map.get("accountDao");
        IAccountDao o = null;
        try {
            o = (IAccountDao) Class.forName(name).newInstance();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return o;
    }

    public static void main(String[] args) {

    }

}
